import { Service } from "egg";

export default class SiliconflowService extends Service {
  // 创建文本对话请求
  async completions(params: { messages: { role: "system" | "user" | "assistant"; content: string }[] }) {
    const { ctx } = this;

    const { messages } = params;

    const client = await ctx.app.siliconflowSdkClient;

    const res = await client.exec("chat/completions", {
      model: "deepseek-ai/DeepSeek-V3",
      messages,
      stream: false,
      max_tokens: 512,
      stop: null,
      temperature: 0.7,
      top_p: 0.7,
      top_k: 50,
      frequency_penalty: 0.5,
      n: 1,
      response_format: {
        type: "text",
      },
    });

    return res;
  }

  // 获取用户模型列表
  async models() {
    const { ctx } = this;

    const client = await ctx.app.siliconflowSdkClient;

    const res = await client.exec("models", {}, { method: "GET" });

    return res;
  }

  async userInfo() {
    const { ctx } = this;
    const client = await ctx.app.siliconflowSdkClient;

    const res = await client.exec("/user/info", {}, { method: "GET" });

    return res;
  }
}
